<?php
/**
 * LeaveMsgController.class.php
 * 留言控制器
 * 
 * @author 	王中艺	<wangzy_smile@qq.com>
 * @date 	2017-05-10
 */

namespace Admin\Controller;

class LeaveMsgController extends BaseController {

	/**
	 * 获取留言列表
	 * @param 	$relate_type 	关联类型
	 * @param   $relate_id 关联ID
	 * @param   $status 留言状态
	 * @param 	$p 	页码数
	 * @return 	$list
	 */
	function getList(){
		$relateType = $this->request('relate_type', false);
		$relateId 	= $this->request('relate_id', false);
		$status 	= $this->request('status', false);
		$page 		= $this->request('p', 1);

		$pageHtml 	= true;
		$list 	= D('LeaveMsg')->getList($relateType, $relateId, $status, $page, $pageHtml);
		if($list === false)
			$this->outOInfo(D('LeaveMsg')->errMsg, 0);

		$this->outOInfo(['list' => $list, 'page_html' => $pageHtml]);
	}

	/**
	 * 变更留言
	 * @param 	$msg_id	留言ID
	 * @param 	$msg_info 	留言信息
	 * @return 	boolean
	 */
	function updateItem(){
		$this->unEmptyParam(['msg_id', 'msg_info']);

		$lMsgId 	= $this->iInfo['msg_id'];
		$lMsgInfo 	= $this->iInfo['msg_info'];

		$result 	= D('LeaveMsg')->updateItem($lMsgId, $lMsgInfo);
		if($result === false)
			$this->outOInfo(D('LeaveMsg')->errMsg, 0);

		$this->outOInfo('Oh yes!');
	}

	/**
	 * 回复留言
	 * @param 	$msg_id 	留言ID
	 * @param 	$content 	回复内容
	 * @return 	boolean
	 */
	function replyItem(){
		$this->unEmptyParam(['msg_id', 'content']);

		$lMsgId 	= $this->iInfo['msg_id'];
		$content 	= $this->iInfo['content'];

		$model 	= new \Think\Model();
		$model->startTrans();

		$result 	= D('LeaveMsg')->replyMsg($lMsgId, $content);
		if($result === false){
			$model->rollback();
			$this->outOInfo(D('LeaveMsg')->errMsg, 0);
		}

		$model->commit();

		$this->outOInfo('Oh yes!');
	}
}